/*
 * @Author: 谢小康 2170673706@qq.com
 * @Date: 2023-12-11 17:01:42
 * @LastEditors: 谢小康 2170673706@qq.com
 * @LastEditTime: 2024-02-06 14:14:28
 * @FilePath: \my_bolg_admin\my_admin\src\store\User.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { defineStore } from 'pinia'
import {ref} from "vue"

export const Userstore = defineStore('user', {
     // 数据存到store里刷新页面会重置，持久化就不会了
  persist: {
    enabled: true, //开启数据持久化
    strategies: [
      {
        key: "user", //给一个要保存的名称
        storage: localStorage, //sessionStorage / localStorage 存储方式
      },
    ],
  },
    state: () => ({ 
        userInfo:{
            username:"",
            Users_corver:"", 
            id:"",
        },
        islogin:false,
     }),
    getters: {
      getuserInfo: (state) => {
        return state.userInfo
      }
    },
    actions: {
        storageUserInfo(userinfo){
            this.userInfo.username = userinfo.Users_name
            this.userInfo.Users_corver = userinfo.Users_corver
            this.userInfo.id = userinfo.id,
            localStorage.setItem("islogin" , true)
        },
        clearuserinfo(){
          this.userInfo.username = ""
          this.userInfo.Users_corver = ""
          this.userInfo.id = ""
        }
    },

})